package com.amigo.online.provider.sync.convert.impl;

import java.util.Map;

import org.apache.solr.common.SolrInputDocument;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.amigo.online.provider.common.entity.VideoMysqlInfo;
import com.amigo.online.provider.sync.abs.BasicSolrDataProjectProperties;
import com.amigo.online.provider.sync.convert.ConvertJsonObjectService;

/**
 * @version: V 1.0.0
 * @Description: （对类进行功能描述）
 * @author: zxy  QQ:1363320658
 * @date: 2018年12月10日 下午4:32:11
 */
@Service("solrVideoConvertServiceImpl")
public class SolrVideoConvertServiceImpl implements ConvertJsonObjectService<SolrInputDocument, JSONObject, VideoMysqlInfo> {

    private static Logger logger = LoggerFactory.getLogger(SolrVideoConvertServiceImpl.class);

    @Autowired
    BasicSolrDataProjectProperties basicSolrDataProjectProperties;

    @Override
    public SolrInputDocument convert(JSONObject source) {
        SolrInputDocument document = new SolrInputDocument();
        Map<String, String> projectMap = basicSolrDataProjectProperties.getVideoProjectMap();
        Map<String, String> classMap = basicSolrDataProjectProperties.getVideoClassMap();
        for (String temp : basicSolrDataProjectProperties.getVideoUpdateList()) {
            String solrVideoFieldName = projectMap.get(temp);
            String solrVideoClassName = classMap.get(temp);
            if (solrVideoFieldName != null) {
                temp = solrVideoFieldName;
            }
            if (solrVideoClassName == null) {
                document.addField(temp, source.get(temp));
            } else {
                try {
                    Class<?> clazz = Class.forName(solrVideoClassName);
                    document.addField(temp, source.getObject(temp, clazz));
                } catch (ClassNotFoundException e) {
                    logger.info("获取video中" + temp + "字段类型失败！");
                }
            }
        }
        return document;
	/*	document.addField("latitude", source.getString("latitude"));	//纬度
		document.addField("video", source.getString("video"));	//视频地址
		document.addField("type", source.getInteger("type"));	//类型
		document.addField("share", source.getInteger("share"));    //分享数量
		document.addField("comment", source.getInteger("comment"));   //评论数量	
		document.addField("content", source.getString("content"));    //视频内容		
		document.addField("cover", source.getString("cover"));    //封面
		document.addField("duration", source.getInteger("duration"));    //视频时长
		document.addField("ads", source.getInteger("ads"));    //是否是广告
		document.addField("user_id", source.getLongValue("user_id"));    //用户id
		document.addField("watermark_video", source.getString("watermark_video"));
		document.addField("width", source.getInteger("width"));  //视频宽
		document.addField("music_id", source.getInteger("music_id")); 		
		document.addField("id", source.getLong("id").toString());    //视频id
		document.addField("up", source.getInteger("up"));  //视频点赞数
		document.addField("longitude", source.getString("longitude")); //纬度
		document.addField("height", source.getInteger("height")); //视频高	
*/
    }

    @Override
    public SolrInputDocument convertBeanToObject(VideoMysqlInfo source) {
        SolrInputDocument document = new SolrInputDocument();
        document.addField("id", source.getId());    //视频id
        document.addField("user_id", source.getUserId());    //用户id
        document.addField("video", source.getVideo());    //视频地址
        document.addField("watermark_video", source.getWaterMarkVideo());
        document.addField("cover", source.getCover());    //封面
        document.addField("duration", source.getDuration());    //视频时长
        document.addField("hred", source.getHref());
        document.addField("type", source.getType());    //类型
        document.addField("ads", source.getAds());    //是否是广告
        document.addField("longitude", source.getLongitude()); //纬度
        document.addField("latitude", source.getLatitude()); //纬度
        document.addField("location_id", source.getLocationId()); //纬度
        document.addField("recommended", source.getLongitude()); //纬度
        document.addField("up", source.getUp());  //视频点赞数
        document.addField("look", source.getLook());  //视频
        document.addField("share", source.getShare());    //分享数量
        document.addField("comment", source.getComment());   //评论数量
        document.addField("content", source.getContent());    //视频内容
        document.addField("music_id", source.getMusicId());
        document.addField("width", source.getWidth());  //视频宽
        document.addField("height", source.getHeight()); //视频高
        document.addField("weight", source.getWeight());
        document.addField("allowe_promoted", source.getAllowePromoted());
        return document;
    }

}
